#include <stdio.h>

void printPascalTriangle(int n) {
    if (n <= 0) return;

    // 定义一个二维数组来存储杨辉三角的值
    int triangle[20][20];

    // 计算杨辉三角的值
    for (int line = 0; line < n; ++line) {
        for (int i = 0; i <= line; ++i) {
            if (i == 0 || i == line) {
                triangle[line][i] = 1;
            } else {
                triangle[line][i] = triangle[line - 1][i - 1] + triangle[line - 1][i];
            }
        }
    }

    // 打印杨辉三角
    for (int line = 0; line < n; ++line) {
        for (int i = 0; i <= line; ++i) {
            printf("%6d", triangle[line][i]);
        }
        printf("\n");
    }
}

int main() {
    int n;
    printf("请输入杨辉三角的行数（n<20）: ");
    scanf("%d", &n);

    if (n >= 20) {
        printf("输入的行数超出范围，请输入小于20的正整数。\n");
        return 1;
    }

    printPascalTriangle(n);

    return 0;
}
